<?php

namespace app\admin\service;

use EasyWeChat\Factory;
use EasyWeChat\Kernel\Messages\Text;
use think\admin\Service;
use think\facade\Db;
use think\facade\Log;

/**
 * 企业用户服务
 * Class WorkUserService
 * @package app\data\service
 */
class WorkUserService extends Service
{
    /**
     * 列表绑定用户数据
     * @param array $list 原数据列表
     * @param string $keys 用户UID字段
     * @param string $bind 绑定字段名称
     * @param string $cols 返回用户字段
     * @return array
     */
    public function buildByUid(array &$list, string $keys = 'uuid', string $bind = 'user', string $cols = '*'): array
    {
        if (count($list) < 1) {
            return $list;
        }
        $uyids = array_unique(array_column($list, $keys));
        $users = $this->app->db->name('work_user')->whereIn('id', $uyids)->column($cols, 'id');
        foreach ($list as &$vo) $vo[$bind] = $users[$vo[$keys]] ?? [];
        return $list;
    }
}